/*
 * Test.java
 *
 * Created on 2007. mo?=rcius 24., 13:47
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */
package laborhazi;
import	java.io.*;

/**
 * Created for testing purpose only to the skeleton phase in the RUP /
 * elaboration
 *
 * @author nyuszik
 */
public class Test {
	
    /* the integer for menu selection*/
    public int testNum;
    /* input storage string */
    private String input;
    /* the boolean for the menu exit*/
    private boolean exit;
    /* test purpose Game */
    public  Game game;
    /* test purpose FinishField */
    public  FinishField finish;
    private InputStreamReader stdin;
    private BufferedReader console;
    private PrintStream oldout = System.out;
    private PrintStream out = null;
    
    /** Creates a new instance of Test */
    public Test() throws IOException {
    	
        stdin = new InputStreamReader(System.in);
        console = new BufferedReader(stdin);
        /* init variables */
        exit = false;
        testNum = -1;
        /*menu loop*/
        while (exit == false) {
            mainMenu();
            /* input a number */
            input = console.readLine();
            try {
            	testNum = Integer.parseInt(input);
            } catch (NumberFormatException e) {
            	
            }
            
            System.setOut(oldout);
            try {
    			out =
    			    new PrintStream(
    			      new BufferedOutputStream(
    			        new FileOutputStream("test.out", true)));
    		} catch (SecurityException e) {
    			// TODO Auto-generated catch block
    			System.err.println("Check file permissions!");
    			//e.printStackTrace();
    		} catch (FileNotFoundException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    		System.setOut(out);
            
            /*decides what to run*/
    		switch (testNum) {
                case 1: init(); break;
                case 2: generate(); break; 
                case 3: steps_1(); break; 
                case 4: steps_2(); break;
                case 5: steps_3(); break;
                case 6: steps_4(); break;
                case 7: steps_5(); break;
                case 8: steps_6(); break;
                case 9: steps_7(); break;
                case 10: steps_8(); break;
                case 11: falls_1(); break;
                case 12: falls_2(); break;
                case 13: falls_3(); break;
                case 14: recieve_1(); break;
                case 15: recieve_2(); break;
                case 16: recieve_3(); break;
                case 17: recieve_4(); break;
                case 18: use_1(); break;
                case 19: use_2(); break;
                case 20: use_3(); break;
                case 21: use_4(); break;
                case 22: use_5(); break;
                case 23: parseError(); break;
                case 24: freeTest(); break; 
                case 25: exit = true; break;
                default: System.out.println("Invalid input"); break;
            }
    		out.close();
    		System.setOut(oldout);
        }
    }
    
    /** 
     * draw the main menu 
     */
    private void mainMenu(){
    System.out.println("Main menu");
    System.out.println("1.Init");
    System.out.println("2.Startfield generates lemmings");
    System.out.println("3.Lemming steps; ahead:air");
    System.out.println("4.Lemming steps; ahead:stone");
    System.out.println("5.Lemming steps; ahead:lemming");
    System.out.println("6.Lemming steps; ahead:blocker");
    System.out.println("7.Lemming steps; under:air");
    System.out.println("8.Lemming steps; under:lemming");
    System.out.println("9.Lemming steps; under:blocker");
    System.out.println("10.Lemming steps; under:setLemming");
    System.out.println("11.Lemming falls; under:air");
    System.out.println("12.Lemming falls; under:air+too much energy");
    System.out.println("13.Lemming falls; under:stone+too much energy");
    System.out.println("14.Lemming recieves tool; no tool yet");
    System.out.println("15.Lemming recieves tool; owns parachute");
    System.out.println("16.Lemming recieves tool; owns blocker gets explosive");
    System.out.println("17.Lemming recieves tool; owns erector gets drill");
    System.out.println("18.Lemming use erector; erector");
    System.out.println("19.Lemming use barricade");
    System.out.println("20.Lemming use parachute; falling");
    System.out.println("21.Lemming use drill");
    System.out.println("22.Lemming use explosive");
    System.out.println("23.Parse error");
    System.out.println("---------------------------------------------");
    System.out.println("24.Free test");
    System.out.println("25.Exit");
    System.out.println("");
    }
  
    
    private void steps_1() {
    	int rounds;
    	int i;
    	Game game;
    	
    	game = new Game(this, "step_1");
        /*rounds = 1;
        for(i = 0; i < rounds; ++i) {
        	game.stage.update();
        }*/
    }
    
    private void steps_2() {
    	int rounds;
    	int i;
    	Game game;
    	
    	game = new Game(this, "step_2");
        /*rounds = 1;
        for(i = 0; i < rounds; ++i) {
        	game.stage.update();
        }*/
    }
    
    private void steps_3() {
    	int rounds;
    	int i;
    	Game game;
    	
    	game = new Game(this, "step_3");
        /*rounds = 1;
        for(i = 0; i < rounds; ++i) {
        	game.stage.update();
        }*/
    }
    
    private void steps_4() {
    	int rounds;
    	int i;
    	Game game;
    	
    	game = new Game(this, "step_4");
        /*rounds = 2;
        for(i = 0; i < rounds; ++i) {
        	game.stage.update();
        }*/
    }
    
    private void steps_5() {
    	int rounds;
    	int i;
    	Game game;
    	
    	game = new Game(this, "step_5");
        rounds = 1;
        /*for(i = 0; i < rounds; ++i) {
        	game.stage.update();
        }*/
    }
    
    private void steps_6() {
    	int rounds;
    	int i;
    	Game game;
    	
    	game = new Game(this, "step_6");
        /*rounds = 1;
        for(i = 0; i < rounds; ++i) {
        	game.stage.update();
        }*/
    }
    
    private void steps_7() {
    	int rounds;
    	int i;
    	Game game;
    	
    	game = new Game(this, "step_7");
        /*rounds = 1;
        for(i = 0; i < rounds; ++i) {
        	game.stage.update();
        }*/
    }
    
    private void steps_8() {
    	int rounds;
    	int i;
    	Game game;
    	
    	game = new Game(this, "step_8");
        /*rounds = 1;
        for(i = 0; i < rounds; ++i) {
        	game.stage.update();
        }*/
    }
    
    private void falls_1() {
    	int rounds;
    	int i;
    	Game game;
    	
    	game = new Game(this, "falls_1");
        /*rounds = 2;
        for(i = 0; i < rounds; ++i) {
        	game.stage.update();
        }*/
    }
    
    private void falls_2() {
    	int rounds;
    	int i;
    	Game game;
    	
    	game = new Game(this, "falls_2");
        /*rounds = 12;
        for(i = 0; i < rounds; ++i) {
        	game.stage.update();
        }*/
    }
    
    private void falls_3() {
    	int rounds;
    	int i;
    	Game game;
    	
    	game = new Game(this, "falls_3");
        /*rounds = 15;
        for(i = 0; i < rounds; ++i) {
        	game.stage.update();
        }*/
    }
    
    private void recieve_1() {
    	int rounds;
    	int i;
    	Game game;
    	
    	game = new Game(this, "recieve_1");
        /*rounds = 1;
        for(i = 0; i < rounds; ++i) {
        	game.stage.update();
        }*/
    }
    
    private void recieve_2() {
    	int rounds;
    	int i;
    	Game game;
    	
    	game = new Game(this, "recieve_2");
        /*rounds = 1;
        for(i = 0; i < rounds; ++i) {
        	game.stage.update();
        }*/
    }
    
    private void recieve_3() {
    	int rounds;
    	int i;
    	Game game;
    	
    	game = new Game(this, "recieve_3");
       /* rounds = 1;
        for(i = 0; i < rounds; ++i) {
        	game.stage.update();
        }*/
    }
    
    private void recieve_4() {
    	int rounds;
    	int i;
    	Game game;
    	
    	game = new Game(this, "recieve_4");
        /*rounds = 2;
        for(i = 0; i < rounds; ++i) {
        	game.stage.update();
        }*/
    }
    
    private void use_1() {
    	int rounds;
    	int i;
    	Game game;
    	
    	game = new Game(this, "use_1");
        /*rounds = 6;
        for(i = 0; i < rounds; ++i) {
        	game.stage.update();
        }*/
    }
    
    private void use_2() {
    	int rounds;
    	int i;
    	Game game;
    	
    	game = new Game(this, "use_2");
        /*rounds = 1;
        for(i = 0; i < rounds; ++i) {
        	game.stage.update();
        }*/
    }
    
    private void use_3() {
    	int rounds;
    	int i;
    	Game game;
    	
    	game = new Game(this, "use_3");
        /*rounds = 10;
        for(i = 0; i < rounds; ++i) {
        	game.stage.update();
        }*/
    }
    
    private void use_4() {
    	int rounds;
    	int i;
    	Game game;
    	
    	game = new Game(this, "use_4");
        /*rounds = 6;
        for(i = 0; i < rounds; ++i) {
        	game.stage.update();
        }*/
    }
    
    private void use_5() {
    	int rounds;
    	int i;
    	Game game;
    	
    	game = new Game(this, "use_5");
        /*rounds = 6;
        for(i = 0; i < rounds; ++i) {
        	game.stage.update();
        }*/
    }
    
    private void generate() {
    	int rounds;
    	int i;
    	Game game;
    	
    	game = new Game(this, "generate");
        /*rounds = 1;
        for(i = 0; i < rounds; ++i) {
        	game.stage.update();
        }*/
    }
    
    private void init() {
    	int rounds;
    	int i;
    	Game game;
    	
    	game = new Game(this, "init");
        /*rounds = 0;
        for(i = 0; i < rounds; ++i) {
        	game.stage.update();
        }*/
    }
    
    private void parseError() {
    	
    	new Game(this, "error");	
    }
    
    
    private void freeTest() {
    	int rounds;
    	int i;
    	Game freegame;
    	BufferedReader console2;
    	
    	out.close();
		System.setOut(oldout);
    	stdin = new InputStreamReader(System.in);
        console2 = new BufferedReader(stdin);
    	freegame = new Game(this, null);
    	System.out.println("Number of rounds?");
    	try {
			input = console2.readLine();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        rounds = Integer.parseInt(input);
        for(i = 0; i < rounds; ++i) {
        	if (freegame.stage != null) 
        		freegame.stage.update();
        }
    	
    }   

}
